﻿@{

    string modelReference = null;

    if (ViewBag.Sample.HasModel)
    {
        modelReference = ViewBag.Project.Name + ".Models." + ViewBag.Sample.Path + "Model";
    }
}
@RenderPage("~/Views/Samples/Generic/PageDeclaration.cshtml", new
{
    CodeBehind = "Default",
    Inherits = ViewBag.Project.Name + "." + ViewBag.Sample.Path + "." + ViewBag.Sample.Path + "Default",
    Title = ViewBag.Sample.Name,
    RegisterSlickUpload = true,
    Model = modelReference
})
@SampleHelper.BeginSection("head")
    @if (!IsSectionDefined("existing_head"))
    {
    <script type="text/javascript">
        @if (!IsSectionDefined("existing_js"))
        {
            if (!IsSectionDefined("existing_js_startupload"))
            {
                if (ViewBag.Project.ViewEngine != ViewEngine.WebForms)
                {
        <text>
        function startUpload()
        {
            var slickUpload = kw("@SampleHelper.ResolveId("slickUpload")");

            if (slickUpload)
                slickUpload.start();
        }
        </text>
                }
            }
            else
            {
            @RenderSection("existing_js_startupload")
            }
        <text>
        function cancelUpload()
        {
            kw("@SampleHelper.ResolveId("slickUpload")").cancel();

            document.getElementById("cancelButton").style.display = "none";
        }

        @if (!IsSectionDefined("existing_js_onfileselectionchanged"))
        {
        <text>
        function onFileSelectionChanged(data)
        {
            document.getElementById("@SampleHelper.ResolveId("uploadButton")").className = "button" + (kw("@SampleHelper.ResolveId("slickUpload")").get_Files().length > 0 ? "" : " disabled");
        }
        </text>
        }
        else
        {
        @RenderSection("existing_js_onfileselectionchanged")
        }

        function onSessionStarted(data)
        {
            @RenderSection("js_onSessionStarted", false)
            document.getElementById("@SampleHelper.ResolveId("uploadButton")").style.display = "none";

            document.getElementById("cancelButton").style.display = "block";
        }
        
        function onBeforeSessionEnd(data)
        {
            document.getElementById("@SampleHelper.ResolveId("uploadButton")").style.display = "none";
            document.getElementById("cancelButton").style.display = "none";
        }
        </text>
        }
        else
        {
        @RenderSection("existing_js")
        }

        @RenderSection("new_js", false)
    </script>
    }
    else
    {
        @RenderSection("existing_head")
    }
@SampleHelper.EndSection()
@SampleHelper.BeginSection("content", true)
    @SampleHelper.BeginForm("uploadForm", "UploadResult", ViewBag.Sample.Path, "multipart/form-data")
    @if (ViewBag.Project.IsAspNetAjax)
    {
        <asp:ScriptManager ID="scriptManager" runat="server" EnablePartialRendering="true">
        </asp:ScriptManager>               
        <asp:UpdatePanel ID="updatePanelTime" runat="server" UpdateMode="Conditional">
            <ContentTemplate>
                <p>Time: <asp:Label ID="updateLabel" runat="server" /></p>
                <p><asp:Button ID="updateButton" runat="server" Text="Update Time" 
                        onclick="updateButton_Click" /></p>
            </ContentTemplate>
        </asp:UpdatePanel>
        @:<asp:UpdatePanel ID="updatePanel" runat="server" UpdateMode="Conditional">
            @:<ContentTemplate>
    }
        @RenderSection("beforeUploadPanel", false)
        @if (ViewBag.Project.ViewEngine == ViewEngine.WebForms)
        {
        @:<asp:Panel ID="uploadPanel" runat="server">
        }
        else
        {
        @:<div id="uploadPanel">
        }
            @RenderSection("uploadPanelTop", false)
            @if (!IsSectionDefined("existing_uploadPanel_content"))
            {
            <table class="settings">
                <tbody>
                    <tr>
                        <th style="font-weight:bold;border-bottom:solid 1px #ccc">Select files to upload</th>
                    </tr>
                    <tr>
                        <td>
                        @{
                Dictionary<string, string> attributes = new Dictionary<string, string>()
                            {
                                { "Id", "\"slickUpload\"" },
                                { "OnClientUploadSessionStarted", "\"onSessionStarted\"" },
                                { "OnClientBeforeSessionEnd", "\"onBeforeSessionEnd\"" },
                                { "OnClientFileAdded", "\"onFileSelectionChanged\"" },
                                { "OnClientFileRemoved", "\"onFileSelectionChanged\"" },
                                { "CssClass", "\"simple\"" },
                                { "ShowDropZoneOnDocumentDragOver", "\"true\"" },
                                { "Style", "\"overflow:hidden;zoom:1\"" },
                                { "FileSelectorStyle", "\"float:left\"" },
                                { "FileListStyle", "\"clear:both\"" },
                                { "UploadProgressDisplayStyle", "\"clear:both\"" }
                            };

                // TODO: figure out how to make this better
                Context.Items["SlickUploadAttributes"] = attributes;
                        }
                            @RenderSection("beforeSlickUpload", false)
                            @if (!IsSectionDefined("existing_slickupload"))
                            {                                
                            @RenderPage("~/Views/Samples/Generic/SlickUpload.cshtml", new { attributes = attributes })
                            }
                            else
                            {
                            @RenderSection("existing_slickupload")
                            }
                            @RenderSection("afterSlickUpload", false)
                        </td>
                    </tr>
                </tbody>
            </table>
            <p>
                @SampleHelper.RenderButton("uploadButton", "button disabled", "CausesValidation=\"true\"", "onclick=\"startUpload()\"", null, @<span><b class="icon upload"></b> Upload Files</span>, includeWebFormsClick: (Page.IncludeWebFormsUploadClick as bool? == true))
                <a id="cancelButton" href="javascript:;" onclick="cancelUpload()" style="display:none" class="button">
                    <span><b class="icon cancel"></b> Cancel</span>
                </a>
                <div style="clear:both"></div>
            </p>
            }
            else
            {
                @RenderSection("existing_uploadPanel_content")
            }
        @if (ViewBag.Project.ViewEngine == ViewEngine.WebForms)
        {
        @:</asp:Panel>
        }
        else
        {
        @:</div>
        }
        @if (ViewBag.Project.ViewEngine == ViewEngine.WebForms)
        {
        <asp:Panel ID="uploadResultPanel" runat="server" Visible="false">
            @if (File.Exists(Server.MapPath("~/views/samples/" + ViewBag.Sample.Path + "/UploadResult.cshtml")))
            {
            @RenderPage("~/views/samples/" + ViewBag.Sample.Path + "/UploadResult.cshtml")
            }
            else
            {
            @RenderPage("~/views/samples/Generic/UploadResult.cshtml")                
            }
        </asp:Panel>
        }
@if (ViewBag.Project.IsAspNetAjax)
{
            @:</ContentTemplate>
        @:</asp:UpdatePanel>            
}        
    @SampleHelper.EndForm()
    @RenderBody()
@SampleHelper.EndSection(true)
@if (!string.IsNullOrWhiteSpace(ViewBag.Sample.Configuration))
{
@SampleHelper.BeginSection("configuration")
    <h2>Configuration</h2>
    @Html.Raw(ViewBag.Sample.Configuration)
@SampleHelper.EndSection()
}
@SampleHelper.BeginSection("description")
    @Html.Raw(ViewBag.Sample.Description)
@SampleHelper.EndSection()